<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>图书馆管理系统</title>
    <!--jquery-->
    <script src="./Resources/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="./Resources/bootstrap.min.css">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="./Resources/bootstrap.min.js"></script>
    <style type="text/css">
        td {
            vertical-align: middle !important;
        }
    </style>
</head>

<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav" aria-expanded="false">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="JavaScript:void(0)">
                    <b>图书馆管理系统</b>
                </a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="nav">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="?p=Admin&c=Index&a=index">主页</a>
                    </li>
                    <li>
                        <a href="?p=Admin&c=Book&a=index">图书管理</a>
                    </li>
                    <li class="active">
                        <a href="?p=Admin&c=User&a=index">用户管理</a>
                    </li>
                    <li>
                        <a href="?p=Admin&c=Borrow&a=index">借阅管理</a>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="JavaScript:void(0)" style="cursor:default">{<$smarty.session.userId>}</a>
                    </li>
                    <li>
                        <a href="?p=Common&c=Login&a=logout">退出</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>
    <div class="container-fluid">
        <div style="width:300px;" class="center-block">
            <div class="form-inline">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="输入搜索内容" id="input" style="width:130px;"
                    {<if $mode == name>}value='{<$smarty.get.name>}'{<else if $mode == userId>}value='{<$smarty.get.userId>}'{</if>}>
                </div>
                <div class="form-group">
                    <select name="type" class="form-control">
                        <option value="num" {<if $mode == userId>}selected{</if>}>ID查询</option>
                        <option value="name" {<if $mode == name>}selected{</if>}>姓名查询</option>
                    </select>
                </div>
                <div class="form-group">
                    <button type="button" id="research" class="btn btn-primary">搜索</button>
                </div>
            </div>
        </div>
        <div class="container">
            <a class="btn btn-info pull-right" href="?p=Admin&c=User&a=add" style="margin:15px 10px 10px;">添加用户</a>
            <table class="table table-bordered table-hover text-center">
                <thead>
                    <tr class="active">
                        <th class="text-center">用户ID</th>
                        <th class="text-center">姓名</th>
                        <th class="text-center">班级</th>
                        <th class="text-center">最后登陆时间</th>
                        <th class="text-center">状态</th>
                        <th class="text-center" style="width:70px;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {<if empty($users)>}
                        <tr>
                            <td colspan="6">无记录！</td>
                        </tr>
                    {</if>}
                    {<foreach $users as $user>}
                        <tr>
                            <td>{<$user.id>}</td>
                            <td>{<$user.name>}</td>
                            <td>{<$user.class>}</td>
                            <td>{<$user.last_login_time>}</td>
                            {<if $user.status == 1>}
                                <td class="success">正常</td>
                            {<else>}
                                <td class="danger">挂失</td>
                            {</if>}
                            <td>
                                <a href="?p=Admin&c=User&a=manage&id={<$user.id>}" class="btn btn-primary btn-xs">详情</a>
                            </td>
                        </tr>
                    {</foreach>}
                </tbody>
            </table>
        </div>
        <!-- 分页 -->
        {<$pageStr>}
</body>
<script>

    $(function(){

        //注册回车查找
        $("#input").keydown(function(event){
            if(event.keyCode == 13){
                $("#research").click();
            }
        });
        //查找
        $("#research").click(function(){
            if($("#input").val().length > 0){
                if($("[name='type']").val() == "name"){
                    var mode = "name";
                }else if($("[name='type']").val() == "num"){
                    var mode = "userId";
                }
                location.href = "?p=Admin&c=User&a=index&"+ mode + "=" + $("#input").val();
            }else{
                alert("请输入搜索条件");
            }
        });

    })

</script>

</html>